﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data;
using MySql.Data.Common;
using MySql.Data.MySqlClient;

namespace Repository.DAL.Supports
{
    internal class MySqlDBFactory:IDBFactory
    {
        #region IDBFactory 成员

        public System.Data.Common.DbConnection CreateConnection()
        {
            return new MySqlConnection();
        }

        public System.Data.Common.DbCommand CreateCommand()
        {
            return new MySqlCommand();
        }

        public string BuildParameterName(string name)
        {
            return name.Insert(0, "?");
        }

        public System.Data.Common.DbParameter CreateParameter(System.Data.Common.DbCommand cmd)
        {
            return cmd.CreateParameter();
        }

        public void AddParameter(System.Data.Common.DbCommand cmd, string name, System.Data.DbType dbType, object value)
        {
            var p = cmd.CreateParameter();
            p.DbType = dbType;
            p.ParameterName = name;
            p.Value = value;
            cmd.Parameters.Add(p);
        }

        #endregion
    }
}
